export default function useCountdown() {
  const count = ref(60);
  const { pause, resume, isActive } = useIntervalFn(
    () => {
      if (count.value > 0) {
        count.value--;
      } else {
        // 停止倒计时
        pause();
      }
    },
    1000,
    // 不要立即执行倒计时
    { immediate: false }
  );
  // 开始倒计时，接收倒计时秒数
  const start = (seconds: number) => {
    if (isActive.value) return;
    count.value = seconds;
    resume();
  };
  return { count, start, isActive };
}
